<?php
namespace Plu\qdh\Controllers\Api;
use Plu\qdh\Controllers\Api\ControllerBase;
use Plu\qdh\Services\ProductService;
use Plu\qdh\Services\ThirdService;


/**
 * @RoutePrefix("/api")
 */
class IndexController extends ControllerBase {
	/**
	 * @Get('/getLayout')
	 * @cache_control("max-age=60")
	 * 获取首页栏目
	 */
    public function indexAction() {
		$service = new ProductService;
		$layOut  = $service->getAllPlatform();
		return $this->release([
			'code'  => 200,
			'items' => $layOut
		]);
	}


	/**
	 * @Get('/getProjects')
	 * @cache_control("max-age=60")
	 * 获取项目列表
	 */
	public function getProjectsAction() {
		$projectId = $this->request->getQuery('platformId');
		if (!$projectId) {
			return $this->release([
				'code'  => 201,
				'items' => [] 
			]);
		}
		$service = new ProductService;
		$items   = $service->getProjectsByPlatform($projectId);
		return $this->release([
			'code'  => 200,
			'items' => $items
		]);
	}

	/**
	 * @Get('/getProjectDetail')
	 * @cache_control("max-age=60")
	 * 获取项目简介
	 */
	public function getProjectDetailAction() {
		$projectId = $this->request->getQuery('projectId');
		if (!$projectId) {
			return $this->release([
				'code'  => 201,
				'items' => [] 
			]);
		}
		$service = new ProductService;
		$items   = $service->getProjectInfo($projectId);
		return $this->release([
			'code'  => 200,
			'items' => $items
		]);
		
	}

	/**
	 * @Get('/getProductDetail')
	 * @cache_control("max-age=60")
	 * 获取商品价格
	 */
	public function getProductDetailAction() {
		$productId = $this->request->getQuery('productNo');
		$service   = new ProductService;
		$items     = $service->getProductDetail($productId);
		return $this->release([
			'code'  => 200,
			'items' => $items
		]);
	}


	/**
	 * @Get('/getProductDaliyInfo')
	 * @cache_control("max-age=60")
	 * 获取商品价格日历表
	 */
	public function getProductDaliyInfoAction() {
		$productNo = $this->request->getQuery('productNo');
		if (!$productNo) {
			return $this->release([
				'code'  => 201,
				'items' => []
			]);
		}
		$service   = new ThirdService;
		$service->setProductNo($productNo);
		$items     = $service->getProductDaliyInfo();
		return $this->release([
			'code'  => 200,
			'items' => $items
		]);
	}

	
}
?>
